package cn.wxxyhw.server;

import cn.wxxyhw.Dao.UserDao;
import cn.wxxyhw.Entity.User;
import cn.wxxyhw.Util.SendMail;
import org.springframework.stereotype.Service;

/**
 * 注册
 * @Author: 洪稳
 * @Date: 2019/6/3
 */

@Service
public class Regeist {

    /**
     * 邮件发送
     * @param username
     * @param email
     * @param code
     * @return
     */
    public static String sendEmail(String username,String email,String code){
        username = "欢迎使用WEI BLOG,"+username+"你的验证码是:";
        SendMail.send_163(email,code,username,"WEI BLOG");
        return code;
    }

    /**
     * 检验用户是否存在
     * @param id
     * @return
     */
    public static String isExit(String id){
        UserDao userDao = new UserDao();
        User user = userDao.userIsExit(id);
        if (user!=null){
            return "exit";
        }
        return "noExit";
    }

    /**
     * 注册
     * @param user
     * @return
     */
    public static boolean regeistUser(User user){
        UserDao userDao = new UserDao();
        int regeist = userDao.regeist(user);
        if (regeist>0){
            return true;
        }
        return false;
    }
}
